Thread: [question]Analyzing data in a two-dimensional array[with code]

  1. #1
    Registered User
    Join Date
    Jun 2005
    Posts
    8

    [question]Analyzing data in a two-dimensional array[with code]

    Analyzing data in a two-dimensional array

    Acknowledgement

    This part of the lab is based on Question 50 in Chapter 5 of Etter's "Engineering Problem Solving with C"





    Problem

    You are to write a program in C that:



    reads data from a file into a one-dimensional array
    writes the corresponding normalized data to another file


    One common normalization technique for a data set is to scale the data in such a way that the minimum value becomes 0.0 and the maximum value becomes 1.0. To achieve this scaling each data point xi is normalized using the formula:



    Normalized xi = ( xi - min ) / ( max - min )



    where min and max are the minimum and maximum data points in the data set. Note that when you set xi to min in this formula, the result is 0. Further, when you set xi to max, the result is 1.



    You should assume that the file contains only the data to be normalized. There is no sentinel value at the end of the file and there is no integer at the beginning of the file to indicate the number of data elements. You should assume that each data element is separated by whitespace (either a space, tab or new line character or a combination of these).






    Developing a test suite

    Before you write your program, develop a test suite that can be used to test your program once it is written. To do this, you will need to create your own data files input0.txt, input1.txt, ...



    Having chosen your test input files, compute by hand the expected output files. After you have written your program, you can then test your program with each of your test files and check that your program produces the expected value. If it doesn't, you probably have one or more logic errors in your code.





    Algorithm development

    Sketch out, in point form, an algorithm for solving the problem. Draw a module chart (as described in Section 1 of Chapter 4) that includes the following functions:



    getMinVal: a function that takes a one-dimensional array of integers and the number of values in the array as its only parameters and returns the minimum value in the array
    getMaxVal: a function that takes a one-dimensional array of integers and the number of values in the array as its only parameters and returns the maximum value in the array
    normalize: a function that takes two arrays and the number of values in the arrays (assume they are the same size) as its only parameters. The first array is a one-dimensional array of integers that contains the original data to be normalized according to the technique described above. The second array is a one-dimensional array of doubles that will contain the normalized data.



    You will use these functions in your program to carry out the specified task.





    Coding

    Create a new project in Dev-C++ and implement your algorithm in C. Be sure to include the three functions described in the previous section. Remember to first implement your functions as stubs and to compile your code before attempting to implement any of the functions. Remove any syntax errors before proceeding further. Implement your functions one at a time. Compile your code after implementing each function and remove any syntax errors as you go. Read the Guide to Dev-C++ for instructions on how to create a new project, edit your source code, and compile and run your program.





    Testing

    Once your code has successfully compiled, verify that it produces correct results using the test suite that you developed earlier. If any of your tests fails, you must look for logic errors in your algorithm (which will, of course, have resulted in logic errors in your code!)





    Debugging

    Now that the programs that you are writing are becoming a little more complex, you might find it useful to use the debugger that is integrated into the Dev-C++ environment. Read the Guide to debugging with Dev-C++ for instructions on how to use the debugger.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    FILE* inputFile;
    FILE* outputFile;
    
    inputFile = fopen( "myInputFile.txt" , "r" );
    outputFile = fopen( "myOutputFile.txt" , "w" );
    
    int main (void){
        
        
        
    
    system ("PAUSE");
    return 0;
    }
    
    /*
    read data from a file and write data to a file
    
    but i dont know how to read a file data to a array.
    
    what is corresponding normalized data?
    */
    

  2. #2
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401
    First, you'll need some input files (you'd know this if you read the directions).
    Quote Originally Posted by burbose
    Before you write your program, develop a test suite that can be used to test your program once it is written. To do this, you will need to create your own data files input0.txt, input1.txt, ...

    You should assume that the file contains only the data to be normalized. There is no sentinel value at the end of the file and there is no integer at the beginning of the file to indicate the number of data elements. You should assume that each data element is separated by whitespace (either a space, tab or new line character or a combination of these).
    The structure of your input file should give you some clues on how to read it.

    Further, the instructions explain what normalized data is.
    Quote Originally Posted by burbose
    One common normalization technique for a data set is to scale the data in such a way that the minimum value becomes 0.0 and the maximum value becomes 1.0. To achieve this scaling each data point xi is normalized using the formula:

    Normalized xi = ( xi - min ) / ( max - min )

    where min and max are the minimum and maximum data points in the data set. Note that when you set xi to min in this formula, the result is 0. Further, when you set xi to max, the result is 1.
    Normalized data is useful for comparing two different sets of data against each other. Basically, you're trying to scale the data so that two different sets of data will be meaningful when compared to each other.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  3. #3
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905
    These sound like end of year projects....how is it that you don't know how to read a file of all things?

    Astonishing....

  4. #4
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401
    Quote Originally Posted by jverkoey
    These sound like end of year projects....how is it that you don't know how to read a file of all things?

    Astonishing....
    Not really. If all the OP has been doing is posting his homework assignments to online forums and gather answers (a view supported by the OP's first two posts), then it's a testament to his resourcefulness that he has managed to get this far.

    *Use of the singular masculine pronoun is not meant as gender-bias. It's just simpler to write "he" than it is to write "he/she" every time.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  5. #5
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    You will not get this done for you here. I linked the board policy on homework to the last 2 threads of yours I had to close. If I have to close another one, it will be your last.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bitmasking Problem
    By mike_g in forum C++ Programming
    Replies: 13
    Last Post: 11-08-2007, 12:24 AM
  2. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 05:49 PM
  3. Two Dimensional Array Input from Formatted Data
    By teedoff087 in forum C Programming
    Replies: 14
    Last Post: 04-29-2007, 01:46 AM
  4. Program Crashing
    By Pressure in forum C Programming
    Replies: 3
    Last Post: 04-18-2005, 10:28 PM
  5. How do I base size of arrays on annother number?
    By Dual-Catfish in forum C++ Programming
    Replies: 15
    Last Post: 09-25-2001, 01:31 PM